const defaultLoaders = require('./defaultLoaders')
const path = require('path')
// const __define__ = require(path.resolve(__dirname, '../../../defineConfig'))
const __define__ = require('../../core-config/index')


const aa = {
  test: /\.ts$|.tsx/,
  use: [{
    loader: 'esbuild-loader',
    options: {
      loader: 'tsx', // Or 'ts' if you don't need tsx
      target: 'es2015'
    }
  },],
  exclude: /node_modules/
}


const esbuild_tsx = {
  test: /\.js$|.jsx/,
  loader: 'esbuild-loader',
  exclude: /node_modules/,
  options: {
    loader: 'jsx',
    target: 'es2015',
    // implementation: esbuild
  }
}


class resolveLoaders {

  constructor(options) {
    this.defaultLoaders = defaultLoaders
    this.options = options
    this.sassLoader = {
      test: /\.s[ac]ss$/i,
      use: [{
        loader: "style-loader"
      }, {
        loader: "css-loader",
        options: {
          modules: {
            localIdentName: "[name]-[local]-[hash:5]"
          }
        }
      }, {
        loader: 'postcss-loader',
        options: {
          postcssOptions: {
            plugins: [
              ['postcss-preset-env']
            ],
          },
        }
      }, {
        loader: "sass-loader"
      }],
    }

  }


  generateLoaders = () => {
    if (__define__.sass) {
      this.defaultLoaders.unshift(this.sassLoader)
    }
    return this.defaultLoaders
  }

}


const loaders = new resolveLoaders().generateLoaders()
module.exports = loaders